package com.itheima.springbootwebtlias.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.springbootwebtlias.mapper.OperateLogMapper;
import com.itheima.springbootwebtlias.pojo.OperateLog;
import com.itheima.springbootwebtlias.pojo.PageResult;
import com.itheima.springbootwebtlias.service.LogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Slf4j
@Service
public class LogServiceImpl implements LogService {

    @Autowired
    private OperateLogMapper operateLogMapper;

    // 分页查询日志列表
    @Override
    public PageResult page(Map<String, String> map) {
        Integer  page = Integer.parseInt(map.get("page"));
        Integer pageSize = Integer.parseInt(map.get("pageSize"));

        log.info("分页查询，参数：{},{}",page, pageSize);

        PageHelper.startPage(page, pageSize);

        Page<OperateLog> pageData = operateLogMapper.selectAll();

        PageResult pageResult = new PageResult(pageData.getTotal(), pageData.getResult());
        return pageResult;
    }

}
